package com.hqyj.dao;

import com.hqyj.pojo.UserInfo;
import com.hqyj.pojo.UserSerInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 关于userinfo的数据库操作
 */
@Mapper//这个借口执行的mybatis的数据库操作
public interface UserInfoDao {
    //登录
    @Select("select * from userInfo where userName=#{userName} and userPwd=#{userPwd}")
    UserInfo login(UserInfo user);

    @Select("select * from managerinfo where managerNickName=#{userName} and managerPwd=#{userPwd}")
    UserInfo loginT(UserInfo user);

    //邮箱登录
    @Select("select * from userInfo where userEmail=#{userEmail}")
    UserInfo selecte(UserInfo user);

    //验证用户名是否重名
    @Select("select count(*) from userInfo where userName=#{userName}")
    int valName(UserInfo user);
    //验证手机号是否已经被注册
    @Select("select count(*) from userInfo where userTel=#{userTel}")
    int valTel(UserInfo user);

    //验证用户经理是否存在是否存在
    @Select("select count(*) from managerinfo where managerName=#{userManager}")
    int valmanager(UserInfo user);

    //验证邮箱是否重名
    @Select("select count(*) from userInfo where userEmail=#{userEmail}")
    int valEmail(UserInfo user);

    //查询用户名是否存在，并且取出盐值
    @Select("select * from userInfo where userName=#{userName}")
    UserInfo selectByName(UserInfo user);
    //注册
    @Insert("insert into userInfo (userName,userPwd,salt,userPhoto,userBir,userSex,userEmail,userEdu,userIdCard,userUnit,userManager,userTel,name,userText) values (#{userName},#{userPwd},#{salt},#{userPhoto},#{userBir},#{userSex},#{userEmail},#{userEdu},#{userIdCard},#{userUnit},#{userManager},#{userTel},#{name},#{userText})")
    int zhuce(UserInfo user);

    //查询userEducation
    @Select("select * from userInfo")
    List<UserInfo> select();

    //根据userid查询
    @Select("select * from userInfo where userId=#{userId}")
    UserInfo selectByUserId(UserInfo user);

    //修改
    @Update("update userInfo set userName = #{userName},name = #{name},userSex = #{userSex},userName = #{userName},userBir = #{userBir},userTel = #{userTel},userEmail = #{userEmail},userEdu = #{userEdu},userUnit = #{userUnit},userName = #{userName},userManager = #{userManager}, userIdCard = #{userIdCard},userText = #{userText} where userId=#{userId}")
    int update(UserInfo user);
    //删除
    @Delete("delete from userInfo where userId=#{userId}")
    int del(UserInfo user);
    //add
    @Insert("insert into userInfo (userName,userPwd,salt) values (#{userName},#{userPwd},#{salt})")
    int add(UserInfo user);
    //根据编号查询
    @Select("select * from userInfo where userId=#{userId}")
    List<UserInfo> findByUserId(UserInfo user);
    //根据这个用户名查询
    @Select("select * from userInfo where userName=#{userName}")
    List<UserInfo> findByUserName(UserInfo user);
    //修改密码
    @Update("update userInfo set userPwd = #{userPwd} where userId=#{userId}")
    int updatePwd(UserInfo user);

    //修改头像
    @Update("update userInfo set userPhoto = #{userPhoto} where userId=#{userId}")
    int updateHead(UserInfo user);

    //用户信息查询
    @Select("select *from userInfo where userName=#{userName} ")
    UserInfo selectuser(UserInfo user);

    //修改用户信息
    @Update("update userinfo set userName=#{userName},name=#{name},userSex=#{userSex},userBir=#{userBir},userTel=#{userTel},userEmail=#{userEmail},userEdu=#{userEdu},userIdCard=#{userIdCard},userUnit=#{userUnit},userManager=#{userManager},userText=#{userText} where userId=#{userId}")
    int updateUserInfo(UserInfo user);

    //注销用户信息
    @Delete("delete from userInfo where userId=#{userId}")
    int deluse(UserInfo user);

    //查询当前昵称是否存在（重名）
    @Select("select count(*) from userInfo where userName=#{userName} and userId!=#{userId}")
    int seluserName(UserInfo user);

    //查询当前用户的姓名，昵称，电话信息
    @Select("select userName,name,userTel,userManager from userInfo where userName=#{serUserNickName} ")
    UserInfo selectUserSer(UserSerInfo ser);

    //分页查询
    @Select("select * from userInfo where userManager=#{userManager}")
    List<UserInfo> selectd(UserInfo user);

    //根据编号查询
    @Select("select * from userInfo where userId=#{userId} and userManager=#{userManager}")
    List<UserInfo> findByUserIdd(UserInfo user);

    //根据用户名查询
    @Select("select * from userInfo where userName=#{userName} and userManager=#{userManager}")
    List<UserInfo> findByUserNamed(UserInfo user);

    //根据userId查询
    @Select("select * from userInfo where userId=#{userId}")
    UserInfo selectByUserIdd(UserInfo user);

    //修改经理个人信息
    @Update("update userInfo set userName=#{userName},name=#{name},userSex=#{userSex}," +
            "userBir=#{userBir},userTel=#{userTel},userEmail=#{userEmail},userEdu=#{userEdu}," +
            "userIdCard=#{userIdCard},userUnit=#{userUnit},userManager=#{userManager},userText=#{userText} " +
            "where userId=#{userId}")
    int updateSelf(UserInfo user);

    //删除
    @Delete("delete from userInfo where userId=#{userId}")
    int dell(UserInfo user);

    //验证用户名是否重名
    @Select("select count(*) from userInfo where userName=#{userName} and userId!=#{userId}")
    int valNamed(UserInfo user);

    //查询今天生日，且属于当前登录的管理员的客户的个人信息select * from userinfo where Month(userBir)='02' and DAY(userBir)='17'
    @Select("select * from userInfo where Month(userBir)=#{monthNow} and DAY(userBir)=#{dayNow}")
    List<UserInfo> selectUserByBir(UserInfo user);
}
